
<?php  	
	header('Content-Type:application/json');
	$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 //用于返回测试值
  $log='';

	
  
mysql_select_db("test", $con);


//默认随机查询一条
$sqlstr="SELECT t1.* FROM `table01` AS t1 JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM `table01`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id ASC LIMIT 1;";
if($_GET["radom"]=='false'){
//判断选择参数
	$star='';
	if($_GET["check_star"]=='true'){
		$star="and star=".$_GET["star"];
	}
	$lastdate='';
	if($_GET["check_lastdate"]=='true'){
		$lastdate=" and lastdate >= DATE_SUB(curdate(), interval ".$_GET["lastdate"]." DAY) ";
	}

	$sqlstr="SELECT t1.* FROM `table01` AS t1 JOIN (SELECT ROUND(RAND()*(SELECT MAX(id) FROM `table01` where 1=1 ".$star.$lastdate.")) AS id) AS t2 WHERE t1.id >= t2.id ".$star.$lastdate." ORDER BY t1.id ASC LIMIT 1;";
	if($_GET["lastnum"]=='true'){
		$sqlstr="SELECT * FROM `table01` WHERE 1=1 ".$star.$lastdate." ORDER BY lastnum ASC LIMIT 1;";
	}
}
//print_r($sqlstr);
$result=mysql_query($sqlstr);
$log=$log.'sqlstr='.$sqlstr;

$row = mysql_fetch_array($result);
$row[]=$log;

mysql_close($con);
	$raw_success =$row;	
	$res_success = json_encode($raw_success);	
	echo $res_success;
	

?> 
